package web.suzy.oj.controller.oj;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import web.suzy.oj.annotation.Access;
import web.suzy.oj.annotation.AccessEnum;
import web.suzy.oj.annotation.AnonApi;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.pojo.entity.discussion.Discussion;
import web.suzy.oj.pojo.vo.DiscussionVO;
import web.suzy.oj.service.oj.DiscussionService;

/**
 * YangSuzy 软件工作室
 * 类名: DiscussionController
 * 描述: ---- 待定 -----
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/12/10 22:55
 */
@RestController
@RequestMapping("/api")
public class DiscussionController {
    @Autowired
    private DiscussionService discussionService;

    /**
     * 方法名: getDiscussionList
     * 描述: 获取讨论列表
     *
     * @param limit       每页显示数目
     * @param currentPage 当前页
     * @param categoryId  分类ID
     * @param pid         题目ID
     * @param onlyMine    是否只读自己
     * @param keyword     关键字
     * @param admin       是否只读管理员
     * @return web.suzy.oj.common.result.ResultBean<com.baomidou.mybatisplus.core.metadata.IPage < web.suzy.oj.pojo.entity.discussion.Discussion>>
     * @date 2022/12/10 22:55
     * @auther YangSuzy
     **/
    @GetMapping("/get-discussion-list")
    @AnonApi
    @Access({AccessEnum.PUBLIC_DISCUSSION})
    public ResultBean<IPage<Discussion>> getDiscussionList(
            @RequestParam(value = "limit", required = false, defaultValue = "10") Integer limit,
            @RequestParam(value = "currentPage", required = false, defaultValue = "1") Integer currentPage,
            @RequestParam(value = "cid", required = false) Integer categoryId,
            @RequestParam(value = "pid", required = false) String pid,
            @RequestParam(value = "onlyMine", required = false, defaultValue = "false") Boolean onlyMine,
            @RequestParam(value = "keyword", required = false) String keyword,
            @RequestParam(value = "admin", defaultValue = "false") Boolean admin) {
        return discussionService.getDiscussionList(limit, currentPage, categoryId, pid, onlyMine, keyword, admin);
    }

    /**
     * 方法名: getDiscussion
     * 描述: 根据讨论ID获取讨论详情
     *
     * @param did 讨论ID
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.vo.DiscussionVO>
     * @date 2022/12/10 23:11
     * @auther YangSuzy
     **/
    @GetMapping("/get-discussion-detail")
    @AnonApi
    public ResultBean<DiscussionVO> getDiscussion(@RequestParam(value = "did") Integer did) {
        return discussionService.getDiscussion(did);
    }

    /**
     * 方法名: addDiscussion
     * 描述: 用户发布讨论
     *
     * @param discussion 讨论
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/12/10 23:33
     * @auther YangSuzy
     **/
    @PostMapping("/discussion")
    @RequiresPermissions("discussion_add")
    @RequiresAuthentication
    @Access({AccessEnum.PUBLIC_DISCUSSION})
    public ResultBean<Void> addDiscussion(@RequestBody Discussion discussion) {
        return discussionService.addDiscussion(discussion);
    }
}
